﻿Namespace Midline
    Public Class bpd
        Public E0 As Double
        Public T As Double '切线长
        Public R As Double   '已知
        Public i1 As Double '左接直线坡度'上坡为正，已知
        Public i2 As Double '右接直线坡度下坡为负，已知
        Public aotu As Integer  '凹凸性
        Public startm As Double
        Public bpdm As Double '已知
        Public endm As Double
        Public elebpd As Double '变坡点高程
        Public elejd As Double  '交点高程   '已知
        Public elestart As Double
        Public eleend As Double
        Public omega As Double  'i2-i1

        ''' <summary>
        ''' 构造
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            aotu = 1
        End Sub
        ''' <summary>
        ''' 初始化
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function initMySelf()
            omega = i2 - i1
            If (omega > 0) Then
                aotu = 1
            Else
                aotu = -1
            End If
            T = R * Math.Abs(omega) / 200
            E0 = T * T / (2 * R)
            elebpd = elejd + aotu * E0
            startm = bpdm - T
            endm = bpdm + T
            '求起止点高程
            elestart = elejd - T * i1 / 100
            eleend = elejd + T * i2 / 100
            Return Nothing
        End Function
        ''' <summary>
        ''' 通过里程计算高程
        ''' </summary>
        ''' <param name="mil"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetEleByMileage(ByRef mil As Double) As Double
            If mil = bpdm Then
                Return elebpd
            ElseIf mil = startm Then
                Return elestart
            ElseIf mil = endm Then
                Return eleend
            End If
            Select Case mil
                Case Is < startm
                    Return elestart - i1 * (startm - mil) / 100
                Case Is > endm
                    Return eleend + i2 * (mil - endm) / 100
                Case bpdm To endm
                    Return eleend - (endm - mil) * i2 / 100 + aotu * Math.Pow((endm - mil), 2) / (2 * R)
                Case startm To bpdm
                    Return elestart + (mil - startm) * i1 / 100 + aotu * Math.Pow((mil - startm), 2) / (2 * R)
            End Select
            Return Nothing
        End Function
    End Class
End Namespace
